package com.hnzq.cloud.controller;


import com.hnzq.cloud.entity.FreType;
import com.hnzq.cloud.model.Result;
import com.hnzq.cloud.param.UpdateFreTypeParam;
import com.hnzq.cloud.service.FreTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jams
 * @since 2022-02-06
 */
@RestController
@RequestMapping("freType")
public class FreTypeController {

    @Resource
    private FreTypeService freTypeService;

    @PostMapping("addFreType")
    public Result addFreType(@RequestParam("name") String name){
        Boolean bool = freTypeService.addFreType(name);
        if (bool){
            return Result.newInstance().setMessage("新增成功");
        }else{
            return Result.newInstance().setMessage("新增失败").setCode(144);
        }
    }

    @DeleteMapping("deleteFreType")
    public Result deleteFreType(@RequestParam("id") Integer id){
        Boolean bool = freTypeService.deleteFreType(id);
        if (bool){
            return Result.newInstance().setMessage("删除成功");
        }else {
            return Result.newInstance().setMessage("删除失败").setCode(144);
        }
    }

    @GetMapping("findAllFreTypes")
    public Result findAllFreTypes(){
        List<FreType> allFreTypes = freTypeService.findAllFreTypes();
        return Result.newInstance().setMessage("查询成功").setData(allFreTypes);
    }

    @PutMapping("updateFreType")
    public Result updateFreType(@RequestBody UpdateFreTypeParam updateFreTypeParam){
        Boolean bool = freTypeService.updateFreType(updateFreTypeParam);
        if (bool){
            return Result.newInstance().setMessage("修改成功");
        }else {
            return Result.newInstance().setMessage("修改失败").setCode(144);
        }
    }
}

